﻿using FluentNHibernate.Cfg;
using NHibernate.Cfg;
using NHibernate.Sidekick.Data.NHibernate;

namespace NHibernate.Sidekick.Services.Data
{
    /// <summary>
    /// Provides access to the NHibernate session.
    /// </summary>
    public static class NSession
    {
        /// <summary>
        /// Gets the <see cref="ISession"/>.
        /// </summary>
        /// <value>The session.</value>
        public static ISession Session
        {
            get { return SessionManager.Instance.GetSession(); }
        }

        /// <summary>
        /// Sets the session factory.
        /// </summary>
        /// <param name="traditionalConfiguration">Standard XML (.hbm.xml) mapping configuration.</param>
        /// <param name="interceptor">The <see cref="IInterceptor"/>.</param>
        /// <returns>The main runtime interface between a .NET application and NHibernate.</returns>
        public static ISession SetSessionFactory(Configuration traditionalConfiguration, IInterceptor interceptor)
        {
            return SessionManager.Instance.SetSessionFactoryAndReturnSession(traditionalConfiguration, interceptor);
        }

        /// <summary>
        /// Sets the session factory.
        /// </summary>
        /// <param name="fluentConfiguration">Strongly typed C# code mapping configuration.</param>
        /// <param name="interceptor">The <see cref="IInterceptor"/>.</param>
        /// <returns>The main runtime interface between a .NET application and NHibernate.</returns>
        public static ISession SetSessionFactory(FluentConfiguration fluentConfiguration, IInterceptor interceptor)
        {
            return SessionManager.Instance.SetSessionFactoryAndReturnSession(fluentConfiguration, interceptor);
        }
    }
}